package com.atguigu.spzx.product.controller;

import com.atguigu.spzx.model.dto.h5.ProductSkuDto;
import com.atguigu.spzx.model.entity.product.ProductSku;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.h5.IndexVo;
import com.atguigu.spzx.model.vo.h5.ProductSkuVo;
import com.atguigu.spzx.product.service.ProductService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "商品模块")
//@CrossOrigin
@RequestMapping("/api/product")
public class ProductController {
    // 微服务之间只会远程调用 不会互相引入依赖
    @Resource
    ProductService productService;
    @Operation(summary = "根据orderNo更新sku销量和库存接口")
    @PutMapping("/updateSkuSalesAndStockByOrderNo/{orderNo}")
    public Result updateSkuSalesAndStockByOrderNo(@PathVariable("orderNo")String orderNo){
        productService.updateSkuSalesAndStockByOrderNo(orderNo);
        return Result.ok();
    }
    @Operation(summary = "根据skuId查询sku数据接口")
    @GetMapping("/findSkuById/{skuId}")
    public Result findSkuById(@PathVariable("skuId")Long skuId){
        ProductSku productSku = productService.findSkuById(skuId);
        return Result.ok().data(productSku);
    }
    @Operation(summary = "查询商品详情页数据接口")
    @GetMapping("/item/{skuId}")
    public Result findItemBySkuId(@PathVariable("skuId")Long skuId){
        ProductSkuVo productSkuVo = productService.findItemBySkuId(skuId);
        return Result.ok().data(productSkuVo);
    }

    @Operation(description = "查询商品列表数据接口")
    @GetMapping("{pageNum}/{pageSize}")
    public Result page(@PathVariable("pageNum")Integer pageNum,
                       @PathVariable("pageSize") Integer pageSize ,
                       ProductSkuDto productSkuDto){
        PageInfo<ProductSku> pageInfo  = productService
                .findPage(pageNum , pageSize , productSkuDto);
        return Result.ok().data(pageInfo);
    }
    @Operation(description = "加载首页商品列表接口")
    @GetMapping("index")
    public Result index(){
        IndexVo indexVo = productService.findIndexVo();
        return Result.ok().data(indexVo);
    }
}
